#!/usr/bin/python
# -*- coding: utf-8 -*-
import re,os,sys,Tool,requests

#返回为数组
def text_getMiddle(origin,left,right):
    left=str(left.replace("#引号","\"").replace("#换行符","\\n")).replace("#冒号",":").replace("#单引号","\'")
    right = str(right.replace( "#引号" , "\"" ).replace("#换行符","\\n")).replace("#冒号",":").replace("#单引号","\'")

    middleList=re.findall( '%s.*?%s' %(left,right) , origin )
    #print(origin)
    #middleList = re.findall( 'name\":\".*?\",', origin )
    #print(middleList)
    for u,middle in enumerate(middleList):
        middleList[u]=middle.replace(left,"").replace(right,"")
    #if len(middleList)==0:
        #print("取中间失败，找不到")
    return  middleList


def file_writeToTxt(filename="undefine.txt",content=""):
    path=os.getcwd( ) + "/"+filename
    f = open( path,"w" )
    f.write( content )

def file_readFile(filename="undefine.txt"):
    path = os.getcwd( ) + "/" + filename
    file = open( filename , 'a+' )  # 打开文件
    file.seek( 0 )  # 移动指针到开头
    return file.read( )

def file_getCurrentFilePath():
    return sys.path[0]

def web_get(url,cookies):
    headers = {
        'Cookie': cookies ,
        'Content-Type': "application/x-www-form-urlencoded"
    }
    # 发送
    req = requests.session( )
    try:
        rs = req.get( url=url , headers=headers )
        return rs.text
    except Exception:
        return "input cause excption"

def web_post(url,content,cookies):
    headers = {
        'Cookie': cookies ,
        'Content-Type': "application/x-www-form-urlencoded"
    }
    # 发送
    req = requests.session( )
    rs = req.post( url=url , data=content , headers=headers )
    return rs.text+"\ncookies: "+str(req.cookies.get_dict())

if __name__ == '__main__':
    print(text_getMiddle("a1ba2ba3b\n11","a","b\n"))
    # f = open( "C:\\Users\\10241982\\PycharmProjects\\untitled\\aa.txt" , "a+" )  # 以追加的方式
    #
    # f.write( "test file" )

    # print( sys.path[0])  # 写完通过\n进行换行
    # os.system(r"cp " + Tool.file_getCurrentFilePath( ) + "\C2.txt  " + Tool.file_getCurrentFilePath( ) + "\scan_result\C2.txt" )